package com.briup.store.web.controller;

import com.briup.common.response.Result;
import com.briup.store.domain.dto.OrderInsertDTO;
import com.briup.store.service.OrderService;
import com.briup.store.domain.vo.OrderGetDetailVO;
import com.briup.store.domain.vo.OrderQueryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orders")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 新增订单
     */
    @PostMapping
    public Result addOrder(@RequestBody OrderInsertDTO orderInsert){
        String orderId = orderService.addOrder(orderInsert);
        return Result.success(orderId);
    }

    /**
     * 查询订单列表
     */
    @GetMapping
    public Result queryOrders(){
        List<OrderQueryVO> orderQuery = orderService.queryOrder();
        return Result.success(orderQuery);
    }


    /**
     * 关闭订单
     */
    @PutMapping("/{id}")
    public Result closeOrder(@PathVariable String id){
        orderService.closeOrder(id);
        return Result.success();
    }

    /**
     * 查看订单详情
     */
    @GetMapping("/{orderId}")
    public Result detailOrder(@PathVariable String orderId){
        OrderGetDetailVO orderGetDetail = orderService.detailOrder(orderId);
        return Result.success(orderGetDetail);
    }
}
